package com.wbao.dianniu.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.listener.IReportListener;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.manager.ReportManager;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.R;

/**
 * 举报
 * 
 * @author yejianjun
 * 
 */
public class ReportActivity extends BaseActivity implements IReportListener {

	private RadioGroup radioGroup;
	private ReportManager manager;
	private Button btn_submit;
	private final int REPORT_TYPE = 1;
	private int objectId;
	private int type;
	private EditText descET;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentLayout(R.layout.activity_report);
		setTitleName("举报");
		getBackView().setImageResource(R.drawable.cancel_res_icon);
		btn_submit = (Button) findViewById(R.id.report_submit);
		radioGroup = (RadioGroup) findViewById(R.id.report_radiogroup);
		descET = (EditText) findViewById(R.id.reason_desc_et);
		manager = new ReportManager(this);
		manager.addReportListener(this);
		type = getIntent().getIntExtra(GlobalContext.INTENT_REPORT_TYPE,0);
		objectId = getIntent().getIntExtra(GlobalContext.INTENT_REPORT_OBJECTID, 0);
		btn_submit.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.report_submit:
			if(-1 ==radioGroup.getCheckedRadioButtonId()){
				Notification.toast(this, "选择举报原因");
				return;
			}
			RadioButton radioButton = (RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
			manager.report(GlobalContext.accountId, REPORT_TYPE, objectId, radioButton.getText().toString(), descET.getText().toString().trim());
			break;

		default:
			break;
		}
	}
	
	@Override
	public void onReportFailure(int errorCode, String errorMsg) {
	}

	@Override
	public void onReportSuccess() {
		Notification.toast(this, getResources().getString(R.string.report_success));
		finish();
	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
}
